import request from '@/request';
import { HouseEntity } from '@/entities/HouseEntity';
import BusinessConstant from '@/constant/BusinessConstant';
import { HouseConstant } from '@/constant/HouseConstant';

const PREFIX = BusinessConstant.ROOT_SERVER + '/house';

export default class HouseApi {
  /**
   * 添加房屋信息
   * @param houseReq 房屋信息
   */
  static addHouse(houseReq: HouseEntity.IAddHouseReq) {
    return request({
      method: 'POST',
      url: PREFIX,
      data: houseReq,
    });
  }

  /**
   * 更新房屋信息
   * @param houseReq 房屋信息
   */
  static updateHouse(houseReq: HouseEntity.IUpdateHouseReq) {
    return request({
      method: 'PUT',
      url: PREFIX,
      data: houseReq,
    });
  }

  /**
   * 删除房屋
   * @param id 房屋id
   */
  static delHouse(id: number) {
    return request({
      method: 'PUT',
      url: `${ PREFIX }/admin`,
      data: {id, status: HouseConstant.HouseToStatusMap.delete}
    });
  }

  /**
   * 获取房屋信息
   */
  static getHouse() {
    return request({
      method: 'GET',
      url: PREFIX,
    });
  }

  /**
   * 获取房屋通过关键字
   * @param data
   */
  static getHouseByKeyword(data: HouseEntity.IGetHouseByKeyword) {
    const {keyword, minLat, minLng, maxLat, maxLng} = data;
    return request({
      method: 'GET',
      url: `${ PREFIX }/keyword?keyword=${ keyword }&minLat=${ minLat }&maxLat=${ maxLat }&minLng=${ minLng }&maxLng=${ maxLng }`
    });
  }

  /**
   * 删除房屋图片
   * @param data data
   */
  static delHouseImg(data: { houseId: number, imgName: string }) {
    return request({
      method: 'DELETE',
      url: PREFIX + '/img',
      data,
    });
  }

  /**
   * 分页获取房屋
   */
  static getHousesByPage(
    minLat: number,
    maxLat: number,
    minLng: number,
    maxLng: number
  ) {
    return request({
      method: 'GET',
      url: `${ PREFIX }/page?minLat=${ minLat }&maxLat=${ maxLat }&minLng=${ minLng }&maxLng=${ maxLng }`,
    });
  }

  /**
   * 通过房屋id获取房屋列表
   */
  static getHouseListByHouseId(houseIdList: string) {
    return request({
      method: 'GET',
      url: `${ PREFIX }/list?houseIdList=${ houseIdList }`
    });
  }
}